<template>
	<view>
		<u-sticky :offset-top="h">
			<view class="p1 mianGg">
				<u-search shape="round" :showAction='false' placeholder="请输入关键词搜索相关内容" @search='getList'
					v-model="queryParams.postName"></u-search>
			</view>
		</u-sticky>
		<DaDropdownVue2 :fixedTopValue='h + 44' :dropdownMenu="dropdownMenuList" themeColor="#007aff"
			textColor="#333333" :duration="300" fixedTop @confirm="handleConfirm" @close="handleClose"
			@open="handleOpen">
		</DaDropdownVue2>
		<scroll-view scroll-y @scrolltolower="loadMore" :style="{'height': `calc(100vh - ${upx2px}px)`}"
			:scroll-with-animation="true">
			<!-- 内容区域 -->
			<view v-for="item in gangWeiList">
				<resume :list="item"></resume>
			</view>
			<Loading :status='status'></Loading>

		</scroll-view>


	</view>
</template>

<script>
	import DaDropdownVue2 from '@/components/da-dropdown-vue2/index.vue'
	// import request from '@/utils/request.js';
	import {
		getUserType
	} from '@/utils/auth'
	import {
		postPage,
		postPageTalent
	} from '@/api/zhiwei/zhiwei.js'
	import resume from '@/components/common/resume/resume.vue'
	import Loading from '@/components/loading/loading.vue'
	import {
		getNavigationBarHeight,
		getTitleBarHeight
	} from '@/utils/system.js';
	export default {
		name: "position",
		components: {
			DaDropdownVue2,

			resume,
			Loading
		},
		data() {
			return {
				status: 'loadmore',
				upx2px: uni.upx2px(400),
				userType: '',
				keyword: '',
				gangWeiList: [],
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					postDuty:'',
				},
				
				dropdownMenuList: [{
						title: '职位筛选',
						type: 'cell',
						prop: 'god1',
						showAll: true,
						showIcon: true,
						// value: '2', // 默认内容2
						options: [{
								label: '日结',
								value: 0
							},
							{
								label: '月结',
								value: 1
							},
						],
					},
					{
						title: '行业筛选',
						type: 'cell',
						prop: 'god1',
						showAll: true,
						showIcon: true,
						// value: '2', // 默认内容2
						options: [{
								label: '日结',
								value: 0
							},
							{
								label: '月结',
								value: 1
							},
						],
					},
					{
						title: '薪资范围',
						type: 'cell',
						prop: 'god1',
						showAll: true,
						showIcon: true,
						// value: '2', // 默认内容2
						options: [{
								label: '日结',
								value: 0
							},
							{
								label: '月结',
								value: 1
							},
						],
					},
					{
						title: '企业性质',
						type: 'cell',
						prop: 'god1',
						showAll: true,
						showIcon: true,
						// value: '2', // 默认内容2
						options: [{
								label: '日结',
								value: 0
							},
							{
								label: '月结',
								value: 1
							},
						],
					}
				]
			};
		},
		methods: {
			async postPage(data) {
				let res = await postPage(data)
				if (res.code == 200) {
					if(this.gangWeiList.length < res.total){
						this.gangWeiList=[...this.gangWeiList,...res.rows]
					}else{
						this.status = "nomore"
					}
				}
				console.log(res, "职位列表")
			},
			async searchPostPage(data) {
				let res = await postPage(data)
				if (res.code == 200) {
				
						this.gangWeiList=res.rows
				}
				console.log(res, "职位列表")
			},
			async postPageTalent(data) {
				let res = await postPageTalent(data)
				if (res.code == 200) {
					// this.gangWeiList = res.rows
					if(this.gangWeiList.length < res.total){
						this.gangWeiList=[...this.gangWeiList,...res.rows]
					}else{
						this.status = "nomore"
					}
				}
			},
			async searchPostPageTalent(data) {
				let res = await postPageTalent(data)
				if (res.code == 200) {
					// this.gangWeiList = res.rows
						this.gangWeiList=res.rows
				}
			},
			loadMore() {
				if(this.status == "nomore") return
					
				
				console.log('底部触发')
				this.status = 'loading'
				
				this.queryParams.pageNum += 1
				let type = getUserType()
				// this.getList(this.queryParams)
				if (type == 'user') {
					this.postPage(this.queryParams)
				} else if (type == 'talent') {
					this.postPageTalent(this.queryParams)
				} else {
					this.postPage(this.queryParams)
				}
				
				// if (this.data.pageNum * this.data.pageSize >= this.total) {
				// 				uni.showToast({
				// 					title: '没有更多数据了',
				// 					icon: 'none',
				// 					duration: 1000
				// 				});
				// 				setTimeout(() => {
				// 					uni.hideLoading()
				// 				}, 500)
				// 			} else {
				// 				if (this.data.pageNum <= this.data.pageNum - 1) {
				// 					setTimeout(() => {
				// 						uni.hideLoading()
				// 					}, 500)
				// 				} else {
				// 					uni.showLoading({
				// 						title: '加载中'
				// 					});
				// 					this.data.pageNum++
				// 					this.getList()
				// 				}
				// 				setTimeout(() => {
				// 					uni.hideLoading()
				// 				}, 500)
				// 			}
			},
			handleConfirm(v) {
				console.log('handleConfirm ==>', v)
			},
			handleClose(v) {
				console.log('handleClose ==>', v)
			},
			handleOpen(v) {
				console.log('handleOpen ==>', v)
			},
			// 查詢崗位
			getList(data) {
				console.log(this.queryParams)
				if (this.userType == 'user') {
					this.searchPostPage(this.queryParams)
				} else if (this.userType == 'talent') {
					this.searchPostPageTalent(this.queryParams)
				}
			}

		},

		computed: {
			h() {
				return getNavigationBarHeight() + getTitleBarHeight()
			}
		},
		mounted() {
			let type = getUserType()
			this.userType = type
			if (type == 'user') {
				this.postPage(this.queryParams)
			} else if (type == 'talent') {
				this.postPageTalent(this.queryParams)
			} else {
				this.postPage(this.queryParams)
			}



		}

	}
</script>

<style lang="scss">
	.fixed {
		height: 40rpx;
		position: fixed;
		left: 0;
		right: 0;
		// background-color: indianred;
	}
</style>